package com.yingxin.yxerp.module.organization.vo.resp;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yingxin.yx.framework.commons.constant.CommonConst;
import com.yingxin.yx.framework.commons.constant.PathConst;
import com.yingxin.yx.framework.commons.dto.AttachmentDto;
import com.yingxin.yx.framework.commons.helper.DateHelper;
import com.yingxin.yx.framework.commons.helper.PropertiesHelper;
import com.yingxin.yx.framework.commons.vo.CommonRespVo;
import com.yingxin.yxerp.module.dingtalk.entity.enums.WeComEmployeeStatus;
import com.yingxin.yxerp.module.dingtalk.entity.enums.WeComNativePlaceEnums;
import com.yingxin.yxerp.module.dingtalk.entity.enums.WeComSocialSecurity;
import com.yingxin.yxerp.module.organization.entity.enums.StaffStatus;
import com.yingxin.yxerp.module.organization.helper.SeniorityHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * 用户
 * @author fanchao
 * @since 2021-05-13
 */

@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "UserRespVo对象", description = "用户")
public class UserRespVo extends CommonRespVo {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    private String id;

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "状态 0 禁用 1 启用 5 申请中")
    private String accountStatus;

    @ApiModelProperty(value = "0 未锁定 1 锁定")
    private String lockFlag;

    @ApiModelProperty(value = "姓名")
    private String staffName;

    @ApiModelProperty(value = "用户编号")
    private Integer staffNo;

    /**
     * 钉钉工号
     */
    private String dingStaffNo;

    @ApiModelProperty(value = "试用期 SY 在职 ZZ DLZ 待离职 离职 LZ")
    private String staffStatus;

    @ApiModelProperty(value = "部门id ")
    private String deptId;

    @ApiModelProperty(value = "所属部门id")
    private String deptIds;

    @ApiModelProperty(value = "厂区id ")
    private String companyId;

    @ApiModelProperty(value = "职位id")
    private String staffPositionId;

    @ApiModelProperty(value = "岗位id")
    private String workType;

    /**
     * 岗位职级
     */
    private String positionLevel;

    /**
     * 员工类型value
     */
    private String employeeType;

    /**
     * 员工类型name
     */
    private String employeeTypeName;

    /**
     * 员工状态
     */
    private Integer weComEmployeeStatus;

    private String weComEmployeeStatusName;

    public String getWeComEmployeeStatusName(){
        if( weComEmployeeStatus != null ){
            WeComEmployeeStatus weComEmployeeStatus_ = WeComEmployeeStatus.getEnum( weComEmployeeStatus );
            if( ObjectUtils.isNotEmpty( weComEmployeeStatus_ ) ){
                return weComEmployeeStatus_.getStatusName();
            }
        }
        return null;
    }

    /**
     * 户籍类型
     */
    private String registeredResidenceType;

    /**
     * 户籍类型名称
     */
    private String registeredResidenceTypeName;

    @ApiModelProperty(value = "电话")
    private String phone;

    @ApiModelProperty(value = "微信")
    private String wechatNickname;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "头像")
    private String avatar;

    @ApiModelProperty(value = "身份证号码")
    private String idCardNo;

    @ApiModelProperty(value = "身份证住址")
    private String certAddress;

    @ApiModelProperty(value = "性别 value")
    private String sex;

    @ApiModelProperty(value = "性别")
    private String sexName;

    @ApiModelProperty(value = "生日")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date birthday;

    /**
     * 年龄
     */
    private String age;

    public String getAge(){
        if( birthday != null ){
            return DateHelper.yearCompare( birthday );
        }
        return CommonConst.FALSE;
    }

    @ApiModelProperty(value = "民族Id")
    private String nationId;

    @ApiModelProperty(value = "民族")
    private String nation;

    @ApiModelProperty(value = "政治面貌value")
    private String politicalOutlook;

    @ApiModelProperty(value = "政治面貌name")
    private String politicalOutlookName;

    @ApiModelProperty(value = "婚姻状态value")
    private String maritalStatus;

    @ApiModelProperty(value = "婚姻状态name")
    private String maritalStatusName;

    @ApiModelProperty(value = "籍贯 省")
    private String nativeProvince;

    @ApiModelProperty(value = "籍贯 省 名称")
    private String nativeProvinceName;

    public String getNativeProvinceName(){
        if( StringUtils.isNotBlank( nativeProvince ) ){
            WeComNativePlaceEnums nativePlaceEnums = WeComNativePlaceEnums.getEnum( Integer.valueOf( nativeProvince ) );
            if( ObjectUtils.isNotEmpty( nativePlaceEnums ) ){
                return nativePlaceEnums.getNativePlaceName();
            }
        }
        return null;
    }

    @ApiModelProperty(value = "籍贯 市")
    private String nativeCity;

    @ApiModelProperty(value = "籍贯 区")
    private String nativeDistrict;

    @ApiModelProperty(value = "居住地")
    private String residencePlace;

    @ApiModelProperty(value = "学历value")
    private String education;

    @ApiModelProperty(value = "学历name")
    private String educationName;

    @ApiModelProperty(value = "毕业学校")
    private String graduationSchool;

    @ApiModelProperty(value = "入学日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date weComIntake;

    @ApiModelProperty(value = "毕业日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date graduationTime;

    @ApiModelProperty(value = "专业")
    private String major;

    @ApiModelProperty(value = "紧急联系人")
    private String emergencyContactName;

    @ApiModelProperty(value = "紧急联系人电话")
    private String emergencyContactPhone;

    @ApiModelProperty(value = "紧急联系人地址")
    private String emergencyContactAddress;

    @ApiModelProperty(value = "紧急联系人关系value")
    private String emergencyContactRelationship;

    @ApiModelProperty(value = "紧急联系人关系name")
    private String emergencyContactRelationshipValue;

    @ApiModelProperty(value = "银行卡号码")
    private String bankCardNo;

    @ApiModelProperty(value = "开户行")
    private String bank;

    @ApiModelProperty(value = "首次参加工作时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date joinWorkingTime;

    @ApiModelProperty(value = "工龄")
    private String workAge;

    public String getWorkAge(){
        if( joinWorkingTime != null ){
            return DateHelper.yearCompare( joinWorkingTime );
        }
        return CommonConst.FALSE;
    }

    @ApiModelProperty(value = "入职时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date entryTime;

    /**
     * 司龄（系统计算）
     */
    private String entryAge;

    public String getEntryAge(){
        if( entryTime != null ){
            return DateHelper.yearCompare( entryTime );
        }
        return CommonConst.FALSE;
    }

    @ApiModelProperty(value = "试用期时长value")
    private String probationPeriod;

    @ApiModelProperty(value = "试用期时长name")
    private String probationPeriodName;

    /**
     * 计划转正日期
     */
    private Date planRegularTime;

    @ApiModelProperty(value = "转正时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date regularTime;

    @ApiModelProperty(value = "离职时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date departureTime;

    @ApiModelProperty(value = "证件有效期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date certEndTime;

    @ApiModelProperty(value = "人员档案备注")
    private String remarks;

    @ApiModelProperty(value = "账户信息备注")
    private String accountRemarks;

    @ApiModelProperty(value = "企业微信-职务")
    private String weComPosition;

    // 名称
    @ApiModelProperty(value = "职位名称")
    private String positionName;

    @ApiModelProperty(value = "岗位名称")
    private String workTypeName;

    @ApiModelProperty(value = "部门名称")
    private String deptName;

    @ApiModelProperty(value = "所属所有部门名称")
    private String belongToAllDeptName;

    @ApiModelProperty(value = "当前部门所有上级部门名称")
    private String deptNames;

    @ApiModelProperty(value = "厂区")
    private String companyName;

    @ApiModelProperty(value = "角色描述")
    private String roleDesc;

    // 角色
    @ApiModelProperty(value = "角色")
    private List<UserRolesRespVo> roles;

    @ApiModelProperty(value = "app角色")
    private List<UserRolesRespVo> appRoles;

    @ApiModelProperty(value = "头像附件")
    private AttachmentDto avatarAttachment;

    @ApiModelProperty(value = "签名附件")
    private AttachmentDto signAttachment;

    @ApiModelProperty(value = "员工照片")
    private AttachmentDto photograph;

    @ApiModelProperty(value = "身份证正面")
    private AttachmentDto idCardFrontAttachment;

    @ApiModelProperty(value = "身份证反面")
    private AttachmentDto idCardBackAttachment;

    @ApiModelProperty(value = "学历附件")
    private List<AttachmentDto> educationAttachmentList;

    @ApiModelProperty(value = "工人编号")
    private Integer workerNo;

    /**
     * 钉钉员工 id
     */
    private String dingUserId;

    /**
     * 企业微信用户 id
     */
    private String weComUserId;

    @ApiModelProperty(value = "工人名称")
    private String workerName;

    /**
     * 微信openid
     */
    private String wechatOpenId;

    /**
     * 微信 avatarUrl
     */
    private String wechatAvatarUrl;

    /**
     * 是否允许APP登录，0 否 1 是
     */
    private String isAppLogon;

    public String getUploadContextPath() {
        return PropertiesHelper.getInstance().getProperty(PathConst.CONTEXT_PATH);
    }


    public String getOpenStatus() {
        if (StaffStatus.LZ.equals(staffStatus)) {
            return "-1";
        } else {
            if (StringUtils.isBlank(username)) {
                return "0";
            } else {
                return "1";
            }
        }
    }

    public String getSeniority() {
        return SeniorityHelper.calc(entryTime, departureTime);
    }

    /**
     * 合同公司
     */
    private String contractCompanyName;

    /**
     * 合同类型value
     */
    private String contractType;

    /**
     * 合同类型name
     */
    private String contractTypeName;

    /**
     * 首次合同起始日
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date firstContractStartTime;

    /**
     * 首次合同到期日
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date firstContractEndTime;

    /**
     * 现合同起始日
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date nowContractStartTime;

    /**
     * 现合同到期日
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date nowContractEndTime;

    /**
     * 合同期限value
     */
    private String contractPeriod;

    /**
     * 合同期限name
     */
    private String contractPeriodName;

    /**
     * 续签次数
     */
    private String contractRenewCount;


    /**
     * 姓名(家人)
     */
    private String familyMemberName;

    /**
     * 关系(家人) value
     */
    private String familyMemberRelation;

    /**
     * 关系(家人) name
     */
    private String familyMemberRelationName;

    /**
     * 性别(家人) value
     */
    private String familyMemberGender;

    /**
     * 性别(家人) name
     */
    private String familyMemberGenderName;

    /**
     * 生日(家人)
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date familyMemberBirthday;

    /**
     * 电话(家人)
     */
    private String familyMemberPhone;

    /**
     * 地址(家人)
     */
    private String weComFamilyMemberAddress;


    /**
     * 身份证(人像面)
     */
    private String forntIdCard;

    /**
     * 身份证(国徽面)
     */
    private String rearIdCard;

    /**
     * 学历证书
     */
    private String academicCertificate;

    /**
     * 学位证书
     */
    private String diplomaCertificate;

    /**
     * 前公司离职证明
     */
    private String releaseLetter;

    /**
     * 员工照片
     */
    private String personalPhoto;

    /**
     * 如果此人不在钉钉员工里时，1 = 不离职，不禁用帐号，0 = 离职，禁用账户
     */
    private String isSynchronism;

    /**
     * 企业微信 - 企业邮箱
     */
    private String weComBizEmail;

    /**
     * 企业微信 - 社保状态
     */
    private Integer weComSocialSecurity;

    private String weComSocialSecurityName;

    public String getWeComSocialSecurityName() {
        if( weComSocialSecurity != null ){
            WeComSocialSecurity type = WeComSocialSecurity.getEnum( weComSocialSecurity );
            if( ObjectUtils.isNotEmpty( type ) ){
                return type.getSocialSecurityName();
            }
        }
        return null;
    }

}